var key = 'EFGH2159CD1660AB';  //密钥 8/16/32
var iv = '567BCD45678';

function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var reg_rewrite = new RegExp("(^|/)" + name + "/([^/]*)(/|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    var q = window.location.pathname.substr(1).match(reg_rewrite);
    if (r != null) {
        return unescape(r[2]);
    } else if (q != null) {
        return unescape(q[2]);
    } else {
        return null;
    }
}
function getMd5(data){
	//32位大写
	return CryptoJS.MD5(data).toString().toUpperCase()
}
function getAesString(data, key, iv) {//加密
    var key = CryptoJS.enc.Utf8.parse(key);
    var iv = CryptoJS.enc.Utf8.parse(iv);
    var encrypted = CryptoJS.AES.encrypt(data, key,
        {
            iv: iv,
            mode: CryptoJS.mode.CBC,
            padding: CryptoJS.pad.Pkcs7
        });
    return encrypted.toString();    //返回的是base64格式的密文
}
function getDAesString(encrypted, key, iv) {//解密
    var key = CryptoJS.enc.Utf8.parse(key);
    var iv = CryptoJS.enc.Utf8.parse(iv);
    var decrypted = CryptoJS.AES.decrypt(encrypted, key,
        {
            iv: iv,
            mode: CryptoJS.mode.CBC,
            padding: CryptoJS.pad.Pkcs7
        });
    return decrypted.toString(CryptoJS.enc.Utf8);
}
function getEmailString(name,key){
    let str='用户'+name+'注册申请已通过审核请点击链接设置密码   \n'
    str +='   \n'
    str +='https://zyqing.ml/markPage/pwd?data='
    str += key
    str +='   \n'
    return str
}
function uuid() {
    var s = [];
    var hexDigits = "0123456789abcdef";
    for (var i = 0; i < 36; i++) {
        s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
    }
    s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
    s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
    // s[8] = s[13] = s[18] = s[23] = "-";
    s[8] = s[13] = s[18] = s[23] = "1";
    var uuid = s.join("");
    return uuid;
}

function getPwdKey(){
    return getAES(uuid());
}
function getAES(data) { //加密
   
    var encrypted = getAesString(data, key, iv); //密文
	console.log(encrypted)
    //var encrypted1 = CryptoJS.enc.Utf8.parse(encrypted);
    return encrypted;
}

function getDAes(data) {//解密
   	console.log('beforDAes',data)
    var decryptedStr = getDAesString(data, key, iv);
	console.log(decryptedStr)
    return decryptedStr;
}
function initCloud(){
    
}